<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <script src="../lib/jquery-1.3.2.min.js"></script>
        <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
        <script type="text/javascript" src="qunit.js"></script>
		<script type="text/javascript" src="../core/juxtapo.js"></script>
		<script type="text/javascript" src="test.juxtapo_core.js"></script>
        <script>
        	
            juxtapo.initComplete = function(){
				
			    module("Core");

				test("init",function(){
					ok(true,"initComplete");
				});			    

			    test("addTemplate", function(){
					var t  = juxtapo.addTemplate("test.htm","test.png",{});
					var expected = new juxtapo.designs.LayoutTemplate("test.png",["test.htm"],{});
			        same(t,expected,"We should have a new template");
					juxtapo.addTemplate("test2.htm","test2.png",{});
					juxtapo.addTemplate("test3.htm","test3.png",{});
					equals(juxtapo.designLayoutImages.length,3,"There should be 3 templates")
			    });
			    
			    module("Designs");
			    
			    test("getDesignImageSettings", function(){
			        ok(
						juxtapo.designs.getDesignImageSettings("test.htm"),
						"We should get image settings back"
					);
			        ok(
						juxtapo.designs.getDesignImageSettings("TeSt.htm"),
						"url should be case insensitive"
					);
			        same(
						juxtapo.designs.getDesignImageSettings("nofile.htm"),
						juxtapo.designLayoutImages[0],
						"When there is no match we should get the first template back"
					);
			
			    });
				
				test("Setting transparency",function(){
					juxtapo.designs.show();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.opaque,
						"juxtapo.designs.show() - Design view should be opaque(2)"
						)
					juxtapo.designs.semiTransparent();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.semiTransparent,
						"juxtapo.designs.semiTransparent() - Design view should be semiTransparent(1)"
						)
					juxtapo.designs.hide();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.hidden,
						"juxtapo.designs.hide() - Design view should be hidden(0)"
						)

				});
				test("Switching transparency",function(){
					juxtapo.designs.forward();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.semiTransparent,
						"juxtapo.designs.forward() - Design view should be semiTransparent(1)"
						)
					juxtapo.designs.forward();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.opaque,
						"juxtapo.designs.forward() - Design view should be opaque(2)"
						)
					juxtapo.designs.forward();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.hidden,
						"juxtapo.designs.forward() - Design view should be hidden(0)"
						)
					juxtapo.designs.back();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.opaque,
						"juxtapo.designs.back() - Design view should be opaque(2)"
						)
					juxtapo.designs.back();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.semiTransparent,
						"juxtapo.designs.back() - Design view should be semiTransparent(1)"
						)
					juxtapo.designs.back();
					equals(
						juxtapo.currentDesignView, 
						juxtapo.designViews.hidden,
						"juxtapo.designs.back() - Design view should be hidden(0)"
						)
				});
				
				test("Changing Template",function(){
					equals(
						juxtapo.designCurrentImageIndex,
						0,
						"Current Template should be 0"
					);
					juxtapo.designs.change()
					equals(
						juxtapo.designCurrentImageIndex,
						1,
						"Next Template (should be 1)"
					);
					juxtapo.designs.change()
					equals(
						juxtapo.designCurrentImageIndex,
						2,
						"Next Template (should be 2)"
					);
					juxtapo.designs.change(true)
					equals(
						juxtapo.designCurrentImageIndex,
						1,
						"Previous Template (should be 1)"
					);
				});
				
				test("search",function(){
					same(
						juxtapo.designs.search(""),
						{designs:[],indexes:[]},
						"Blank search should return an object with designs and indexes properties."
					);
					var results = juxtapo.designs.search("test");
					ok(results,"Search for test should not be null");
					equals(
						results.designs.length,
						3,
						"Search for test should give 3 design results"
					);
					equals(
						results.indexes.length,
						3,
						"Search for test should give 3 indexes results"
					);
				});

				/*
				 * Control
				 -----------------------------------------------*/
			    module("Control");
				test("Control Init",function(){
					ok(juxtapo.control.initCompleted,"Control has initialised")
					equals(typeof(juxtapo.controller),"object","Controller element exists");
					ok(juxtapo.controller.onclick,"Controller on click added");
				});

				/*
				 * Error handling
				 -----------------------------------------------*/
				module("Error handling");
				test("init",function(){
					ok(juxtapo.eh.initCompleted,"Error handling init has completed");
					ok(juxtapo.eh.controller,"controller has been created");
					ok(juxtapo.eh.errorsBox,"Errors box has been created");
				});
				test("logInfo",function(){
					var log = juxtapo.eh.logInfo("here's some information");
					ok(!juxtapo.eh.hasError,"Should not think there has been an error after log info");
					equals(
						log,
						juxtapo.eh.errors,
						"logInfo should return the current list of errors"
					);
					juxtapo.eh.logError("an error has occured");
					ok(juxtapo.eh.hasError,"Should now have set the hasError flag");
				});
				
				/*
				 * thumbs
				 -----------------------------------------------*/
				module("Thumbs");
				test("dropDown", function(){
					ok(juxtapo.thumbs.dropDown,"The dropDown should have been created");
					equals(juxtapo.thumbs.dropDown.text(),"+","drop down text should be a plus sign");
					equals(
						juxtapo.thumbs.dropDown.show(),
						true,
						"drop down expanded flag should be true"
					);
					equals(
						juxtapo.thumbs.dropDown.show(false),
						false,
						"drop down expanded flag should be false"
					);
					equals(
						juxtapo.thumbs.dropDown.toggleShow(),
						true,
						"drop down expanded flag should be true"
					);
				});
				test("thumbnails", function(){
					equals(juxtapo.thumbs.rendered,true,"thumbnails should be rendered because the dropdown has been shown");
					var filter = juxtapo.designs.filterBySearch("2");
					ok(filter,"filter has returned an object");
					equals(
						filter.results.indexes.length,
						1,
						"filter should have returned 1 result"
					);
					var filter = juxtapo.designs.filterBySearch("T");
					ok(filter,"filter has returned an object");
					equals(
						filter.results.indexes.length,
						3,
						"searching is not case sensitive. filter should have returned 3 results"
					);
					juxtapo.thumbs.dropDown.show(false);
				});
				
				/*
				 * ui
				 -----------------------------------------------*/
				module("ui");


				/*
				 * utils
				 -----------------------------------------------*/
				module("utils");
				test("date",function(){
					var testDate = new Date("23 Dec 2010, 10:20:30");
					equals(
						juxtapo.utils.date.toShortTimeString(testDate),
						"10:20:30:0",
						"to short time string"
					);
				});
				test("getJsLocation",function(){
					ok(
						juxtapo.utils.getJsLocation("juxtapo.js"),
						"should find the juxtapo js file"
					);
					equals(
						juxtapo.utils.getJsLocation("notincluded.js"),
						null,
						"return null for a file which isn't included"
					);
					
				});
				test("getKeyCombination ",function(){
					same(
						juxtapo.utils.getKeyCombination("23+shift"),
						{ ctrl:false,keyCode:23,shift:true },
						"should return an object with shift true and the key code"
					);
					same(
						juxtapo.utils.getKeyCombination("23+ctrl"),
						{ ctrl:true,keyCode:23,shift:false },
						"should return an object with ctrl true and the key code"
					);
					same(
						juxtapo.utils.getKeyCombination("23+shift+ctrl"),
						{ ctrl:true,keyCode:23,shift:true },
						"should return an object with shift and ctrl true and the key code"
					);
				});
				test("Strings",function(){
					equals(
						juxtapo.utils.String.contains("stringabcstring","abc"),
						true,
						"The string should contain abc"
					);
					equals(
						juxtapo.utils.String.contains("stringABCstring","abc"),
						false,
						"The string should not contain abs as this is case sensitive"
					);
					equals(
						juxtapo.utils.String.contains("stringstring","abc"),
						false,
						"The string should not contain abc at all"
					);
					equals(
						"stringabcstring".juxtapoContains("abc"),
						true,
						"Contains function should also be available through String.juxtapoContains()"
					);
				});



            };
        </script>
    </head>
    <body>
        <h1 id="qunit-header">juxtapo unit test suite</h1>
        <h2 id="qunit-banner"></h2>
        <h2 id="qunit-userAgent"></h2>
        <ol id="qunit-tests">
        </ol>
    </body>
</html>
